package cn.chason678.springbootwebdemo.controller.device;

import cn.chason678.springbootwebdemo.ErrorType;
import cn.chason678.springbootwebdemo.Result;
import cn.chason678.springbootwebdemo.cn.entity.ProDeviceCn;
import cn.chason678.springbootwebdemo.en.entity.ProDeviceEn;
import cn.chason678.springbootwebdemo.service.DevcieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: chason
 * @Date: 2024/1/19 14:44
 * @Description:
 */
@RestController
@RequestMapping("/device")
public class DeviceController {
    @Autowired
    DevcieService devcieService;

    @RequestMapping("/findCnByOnlyCode")
    public Result findCnByOnlyCode(String onlyCode) {
        ProDeviceCn deviceCn = devcieService.getDeviceCnByOnlyCode(onlyCode);
        if (null == deviceCn) {
            return Result.error(ErrorType.DEVICE_UNEXISTS);
        }
        return Result.success(deviceCn);
    }

    @RequestMapping("/findEnByOnlyCode")
    public Result findEnByOnlyCode(String onlyCode) {
        ProDeviceEn deviceEn = devcieService.getDeviceEnByOnlyCode(onlyCode);
        if (null == deviceEn) {
            return Result.error(ErrorType.DEVICE_UNEXISTS);
        }
        return Result.success(deviceEn);
    }

}
